class DDoSDetectionModel(nn.Module):
    """DDoS检测模型"""
    def __init__(self, input_size=83):
        super().__init__()
        self.conv1 = nn.Conv1d(1, 32, kernel_size=5)
        self.relu = nn.ReLU()
        self.pool = nn.MaxPool1d(2)
        self.flatten = nn.Flatten()
        
        # 计算线性层输入大小
        conv_output_size = self._get_conv_output(input_size)
        
        self.fc1 = nn.Linear(conv_output_size, 128)
        self.fc2 = nn.Linear(128, 2)
    
    def _get_conv_output(self, input_size):
        """计算卷积层输出大小"""
        with torch.no_grad():
            dummy = torch.zeros(1, 1, input_size)
            x = self.conv1(dummy)
            x = self.pool(x)
            return x.numel()
    
    def forward(self, x):
        x = self.conv1(x)
        x = self.relu(x)
        x = self.pool(x)
        x = self.flatten(x)
        x = self.fc1(x)
        x = self.relu(x)
        x = self.fc2(x)
        return x